package com.ejlchina.tool.adapter

import android.annotation.SuppressLint
import android.view.LayoutInflater
import android.view.ViewGroup
import androidx.recyclerview.widget.RecyclerView
import com.adolf.androiddemo.R
import com.adolf.androiddemo.databinding.ItemIndexFixDialogBinding
import com.ejlchina.tool.enums.AntiPinchModeEnum

class AntiPinchBottomDialogAdapter(private val dataList: List<AntiPinchModeEnum>,private var selectMode: AntiPinchModeEnum): RecyclerView.Adapter<AntiPinchBottomDialogAdapter.IndexFixDialogViewHolder>() {

    override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): IndexFixDialogViewHolder {
        val binding = ItemIndexFixDialogBinding.inflate(LayoutInflater.from(parent.context),parent,false)
        return IndexFixDialogViewHolder(binding)
    }

    override fun getItemCount(): Int {
        return dataList.size
    }

    fun getSelectMode() = selectMode

    override fun onBindViewHolder(holder: IndexFixDialogViewHolder, position: Int) {
        holder.bindData(dataList[position])
    }

    inner class IndexFixDialogViewHolder(private val binding: ItemIndexFixDialogBinding): RecyclerView.ViewHolder(binding.root){
        @SuppressLint("NotifyDataSetChanged")
        fun bindData(antiPinchModeEnum: AntiPinchModeEnum){
            binding.tvIndex.text = antiPinchModeEnum.info
            binding.root.setOnClickListener {
                selectMode = antiPinchModeEnum
                notifyDataSetChanged()
            }
            val resId = if (antiPinchModeEnum == selectMode) R.drawable.shape_co_9_so_f3f4f6 else R.drawable.shape_co_10_so_white
            binding.tvIndex.setBackgroundResource(resId)
        }
    }
}